//
//  ContactViewController.m
//  Zyachting
//
//  Created by hungnt47 on 11/10/2012.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ContactViewController.h"
#import "ImageViewerController.h"

@implementation ContactViewController
@synthesize scrollView1,scrollView2 ,contactPageController1,contactPageController2 ;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = NSLocalizedString(@"Contacts", @"Contacts");
        self.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:2] autorelease];        
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
//    self.navigationItem.title = @"Z-Yatching Barcos y Apartamentos";
    UILabel* lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [lblTitle setBackgroundColor:[UIColor clearColor]];
    [lblTitle setTextColor:[UIColor whiteColor]];
    [lblTitle setFont:[UIFont boldSystemFontOfSize:12]];
    lblTitle.text = @"Z-Yatching Barcos y Apartamentos";
    [self.navigationItem setTitleView:[lblTitle autorelease]];
    // Do any additional setup after loading the view from its nib.
    right = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"GlossyRightArrow.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(navigateBtnTapped:)];
    [right setTag:1];
    [self.navigationItem setRightBarButtonItem:right];
    left = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"GlossyLeftArrow.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(navigateBtnTapped:)];
    [left setTag:0];
    
    [self.navigationItem setLeftBarButtonItem:left];
    
    self.navigationItem.leftBarButtonItem = nil;
    UIScrollView* scroller1 = [[UIScrollView alloc] initWithFrame:self.view.frame];
    [scroller1 setContentSize:CGSizeMake(320, 700)];
    [self.view addSubview:scroller1];
    ContactPageViewController* contactPage1 = [[ContactPageViewController alloc] initWithNibName:@"ContactPageViewController" bundle:nil];
    [contactPage1 setIndex:0];
    [scroller1 addSubview:contactPage1.view];
    
    self.scrollView1 = [scroller1 autorelease];
    
    UIScrollView* scroller2 = [[UIScrollView alloc] initWithFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [scroller2 setContentSize:CGSizeMake(320, 700)];
    [self.view addSubview:scroller2];
    ContactPageViewController* contactPage2 = [[ContactPageViewController alloc] initWithNibName:@"ContactPageViewController" bundle:nil];
    [contactPage2 setIndex:1];
    [scroller2 addSubview:contactPage2.view];
    
    self.scrollView1 = [scroller1 autorelease];
    self.scrollView2 = [scroller2 autorelease];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(IBAction)navigateBtnTapped:(id)sender
{
    UILabel* lblTitle = (UILabel*)self.navigationItem.titleView;

    if ([sender tag] == 0) {
        //Left
        [UIView animateWithDuration:0.3f animations:^{
            self.scrollView1.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
            self.scrollView2.frame = CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height);
            self.navigationItem.leftBarButtonItem = nil;
            self.navigationItem.rightBarButtonItem = right;
        }];
    }else{
        //Right
        [UIView animateWithDuration:0.3f animations:^{
            self.scrollView1.frame = CGRectMake(-320, 0, self.view.frame.size.width, self.view.frame.size.height);
            self.scrollView2.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
            self.navigationItem.leftBarButtonItem = left;
            self.navigationItem.rightBarButtonItem = nil;
        }];

    }

    if(self.scrollView2.frame.origin.x<1){
        lblTitle.text = @"Golf-Estates Costa Balance S.L";
    }else{
        lblTitle.text = @"Z-Yatching Barcos y Apartamentos";
    }
}
@end
